// https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
// 17. 电话号码的字母组合

#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <limits.h>

using namespace std;

// struct ListNode {
//     int val;
//     ListNode *next;
//     ListNode() : val(0), next(nullptr) {}
//     ListNode(int x) : val(x), next(nullptr) {}
//     ListNode(int x, ListNode *next) : val(x), next(next) {}
// };

// struct TreeNode {
//     int val;
//     TreeNode *left;
//     TreeNode *right;
//     TreeNode() : val(0), left(nullptr), right(nullptr) {}
//     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
//     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
// };



class Solution {
public:
    vector<string> letterCombinations(string digits) {
        if (digits.size() == 0) return result;
        backtrace(digits, 0);
        return result;
    }
private:
    vector<string> result;
    vector<string> tel = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    string group = "";
    void backtrace(string digits, int start_index) {
        if (group.size() == digits.size()) {
            result.push_back(group);
            return;
        }

        for (int i = 0; i < tel[digits[start_index] - '2'].size(); i++) {
            group += tel[digits[start_index] - '2'][i];
            backtrace(digits, start_index + 1);
            group.erase(group.end() - 1);
        }
    }
};



int main() {
    Solution obj = Solution();
    string aa = "23";
    vector<string> qq = obj.letterCombinations(aa);
    for (int i = 0; i <= qq.size(); i++)
        cout << qq[i] << endl;

    return 0;
}